<template>

  <div >
    <div >

      
      <div style="width: 450px;height: 350px;  border: solid 2px;border-radius: 20px ;" class="flex-center shadow-box">
        <el-text class="mx-1" size="large" tag="b">注册账户</el-text>
        <br>
        <el-form :model="form" label-width="auto" style="max-width: 400px " >

          <el-form-item label="用户名" label-position="left">
            <el-input v-model="form.name" />
          </el-form-item>
          
          <el-form-item label="邮箱" label-position="left">
            <el-input v-model="form.email" />
          </el-form-item>

          <el-form-item label="密码" label-position="left">
            <el-input v-model="form.password" />
          </el-form-item>

          <el-button type="primary" @click="onSubmit">注册</el-button>

        </el-form>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from 'vue'
import axios from 'axios';
import { useRouter } from 'vue-router'
const router = useRouter()

// do not use same name with ref
const form = reactive({
  name: '',
  email: '',
  password: ''
})

const onSubmit = () => {
  
var data = JSON.stringify({
   "userName": form.name,
   "password": form.password,
   "email": form.email
});

var config = {
   method: 'post',
   url: 'http://localhost:8080/users/register',
   headers: { 
      'Content-Type': 'application/json'
   },
   data : data
};

axios(config)
.then(function (response) {
   console.log(JSON.stringify(response.data));
})
.catch(function (error) {
   console.log(error);
});
  form.name = '';
  form.email = '';
  form.password = '';
  // 清空输入框

  console.log('submit!')
  //跳转到登录页面 
  router.back('/');
}



// onclick()
// {
//   axios(config)
//   .then(function (response) {
//      console.log(JSON.stringify(response.data));
//   })
//   .catch(function (error) {
//      console.log(error);
//   });
// }
</script>



<style scoped>

.page-container {
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.flex-center {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100px;
  flex-direction: column;
}

.shadow-box {
  background-color: rgb(238, 240, 249);
  width: 300px;
  height: 200px;
  border-radius: 10px;
  border: 2px solid #4285f4;
  padding: 20px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

body {
  background-image: url('src/img/logo.png'); /* 替换为你的图片URL */
  background-repeat: repeat; /* 设置背景图片重复 */
  /* background-size: 100px 100px; 设置背景图片的大小 */
  background-size: 34%;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
} 



</style>